using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Configuration;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class InsertParametersPage : System.Web.UI.Page
{
    GridView gridView;
    SqlDataSource sqlDataSource;
    protected void Page_Load(object sender, EventArgs e)
    {
        sqlDataSource = new SqlDataSource();
        sqlDataSource.ConnectionString =
        WebConfigurationManager.ConnectionStrings[
            "RecruitVietnamDbConnectionString"
            ].ConnectionString;                
        ShowData();
        AddNew("7","Tien Giang","Vietnam");
        ShowData();
    }

    void ShowData()
    {
        sqlDataSource.SelectCommandType =
                SqlDataSourceCommandType.Text;
        sqlDataSource.SelectCommand =
        "select * from tblProvinces";
        gridView = new GridView();
        this.form1.Controls.Add(gridView);
        gridView.DataSource = sqlDataSource;
        gridView.DataBind();

    }

    void AddNew(string provinceID,
    string provinceName, string countryname)
    {

        sqlDataSource.InsertCommandType = 
        SqlDataSourceCommandType.Text;
        sqlDataSource.InsertCommand =
        "insert into tblProvinces values("+
        "@ProvinceID,@ProvinceName,@CountryName)";
        Parameter parameter = new
        Parameter("ProvinceID", 
        TypeCode.Int32, provinceID);
        sqlDataSource.InsertParameters.Add(parameter);

        parameter = new
                Parameter("ProvinceName",
                TypeCode.String, provinceName);
        sqlDataSource.InsertParameters.Add(parameter);

        parameter = new
               Parameter("CountryName",
               TypeCode.String, countryname);
        sqlDataSource.InsertParameters.Add(parameter);
        sqlDataSource.Insert();
        

    }
}
